{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#smo算法，里面的公式很复杂，这里只是简化版本，详细版本请参见原版代码\n",
    "#SMO基本思路：1.选取一对需要更新的alpha(i)和alpha(j) 2.固定其他的alpha,更新这两个值直到收敛\n",
    "#关键：怎么选取两个alpha值？   +  怎么更新？\n",
    "import numpy as np\n",
    "#load data from file导入txt数据\n",
    "def load_data(filename):\n",
    "    dataset = []\n",
    "    label = []\n",
    "    file = open(filename)\n",
    "    for line in file.readlines():\n",
    "        lineArr = line.strip().split('\\t')\n",
    "        m = len(lineArr)\n",
    "        dataset.append(lineArr[0:m-1])\n",
    "        label.append(lineArr[-1])    \n",
    "    return np.array(dataset,dtype=np.float64),\\\n",
    "           np.array(label,dtype=np.int).reshape(-1,1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(100L, 2L) (100L, 1L)\n[ 3.542485  1.977398] [-1]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEKCAYAAAASByJ7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH6xJREFUeJzt3X+QXWd93/H3V7KMvNi1bMk/gPXuOilpMC4W1TqKytRN\ngOnQhMFJppOJZ3EhMKPBod6VHIbB7GAvHTQTEkby7oSEih8tg7ZJW0IbkvGYAkmm0zQxrBwRfthO\nKbGUBbvYCmszVVWE9ts/nnuy516dc++5955zz4/7ec2c2T1n749ndVfP9zzP9/lh7o6IiMi2sgsg\nIiLVoIAgIiKAAoKIiLQoIIiICKCAICIiLQoIIiICKCCIiEiLAoKIiAAKCCIi0nJZ2QXox549e3xm\nZqbsYoiI1MrJkyefc/frej2uVgFhZmaGtbW1soshIlIrZnY6y+PUZSQiIoACgoiItCggiIgIULMc\nQpILFy6wvr7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ej8FhMG8DPib2Pk6DawsI2Y2A7wa\neLTckhTiIeDdwGbZBSnQzYSVhP9tq2vsY2b24rILlRd3/zZh18UzwNPA8+7+X8stVaFucPenW98/\nA9yQ1wsrIEhXZnYl8HvAIXd/oezy5MnM3gh8191Pll2Wgl0G/CPgt9391cD/IcduhrK1+tDvJAS+\nlwIvNrOxWCuttShobkNFFRAG823gptj5ZOtao5jZDkIwWHX3z5RdngK8BniTmT1F6PZ7rZmdKLdI\nhVgH1t09auF9mhAgmuL1wF+7+7PufgH4DPCPSy5Tkf63mb0EoPU1ty2IFRAG82Xg5WZ2s5ldTkhg\nfbbkMuXKzIzQ5/y4ux8tuzxFcPf73X3S3WcIn+EfuXvj7izd/Rngb8zsH7QuvQ74RolFytsZ4CfN\nbKL1d/s6GpQ0T/BZ4C2t799C2I44F2Xth1Br7v5DM/tXwOcIIxo+4e5fL7lYeXsNcDfw1dYe2ADv\ndfeHSyyTDO5eYLV1A/Mt4JdLLk9u3P1RM/s08BhhdNxf0JAZy2b2O8BPAXvMbB14EPg1wrbDbyes\n/vyLub2fZiqLiAioy0hERFoUEEREBFBAEBGRFgUEEREBFBBERKRFAUEkJ2b2iJltNHnVVGk2BQSR\n/PwGYe6GSC0pIIj0ycxuN7O/NLOdZvbi1jr8t7r7F4Hvl10+kUFpprJIn9z9y2b2WeADwBXACXf/\nWo+niVSeAoLIYP41YU2r84TNWURqT11GIoPZDVwJXAU0YrtGEQUEkcH8G+B9wCrwwZLLIpILdRmJ\n9MnM/iVwwd3/fWt/7f9hZq8F3g/8OHBla2XKt7v758osq0g/tNqpiIgA6jISEZEWBQQREQEUEERE\npEUBQUREAAUEERFpUUAQERFAAUFERFoUEEREBID/D6bbAFNTnNHTAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7dfe0f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "#导入数据并且可视化一下\n",
    "x,y = load_data(\"svm/testSet.txt\")\n",
    "print x.shape,y.shape\n",
    "print x[0],y[0]\n",
    "\n",
    "label1 = np.where(y.ravel() == -1)\n",
    "plt.scatter(x[label1,0],x[label1,1],marker='x',color = 'r',label = '-1')\n",
    "label2 = np.where(y.ravel() == 1)\n",
    "plt.scatter(x[label2,0],x[label2,1],marker='o',color = 'b',label = '1')\n",
    "    \n",
    "plt.xlabel('x1')\n",
    "plt.ylabel('x2')\n",
    "plt.legend(loc = 'upper left')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def selectJrand(i,m):\n",
    "    j=i #we want to select any J not equal to i\n",
    "    while (j==i):\n",
    "        j = int(np.random.uniform(0,m))\n",
    "    return j\n",
    "\n",
    "def clipAlpha(aj,H,L):\n",
    "    if aj > H: \n",
    "        aj = H\n",
    "    if L > aj:\n",
    "        aj = L\n",
    "    return aj\n",
    "\n",
    "def smoSimple(dataMatIn, classLabels, C, toler, maxIter):\n",
    "    dataMatrix = np.mat(dataMatIn); labelMat = np.mat(classLabels).transpose()\n",
    "    b = 0; m,n = np.shape(dataMatrix)\n",
    "    alphas = np.mat(np.zeros((m,1)))\n",
    "    iter = 0\n",
    "    while (iter < maxIter):\n",
    "        alphaPairsChanged = 0\n",
    "        for i in range(m):\n",
    "            fXi = float(np.multiply(alphas,labelMat).T*(dataMatrix*dataMatrix[i,:].T)) + b\n",
    "            Ei = fXi - float(labelMat[i])#if checks if an example violates KKT conditions\n",
    "            if ((labelMat[i]*Ei < -toler) and (alphas[i] < C)) or ((labelMat[i]*Ei > toler) and (alphas[i] > 0)):\n",
    "                j = selectJrand(i,m)\n",
    "                fXj = float(np.multiply(alphas,labelMat).T*(dataMatrix*dataMatrix[j,:].T)) + b\n",
    "                Ej = fXj - float(labelMat[j])\n",
    "                alphaIold = alphas[i].copy()\n",
    "                alphaJold = alphas[j].copy()\n",
    "                if (labelMat[i] != labelMat[j]):\n",
    "                    L = max(0, alphas[j] - alphas[i])\n",
    "                    H = min(C, C + alphas[j] - alphas[i])\n",
    "                else:\n",
    "                    L = max(0, alphas[j] + alphas[i] - C)\n",
    "                    H = min(C, alphas[j] + alphas[i])\n",
    "                if L==H:\n",
    "                    #print \"L==H\"\n",
    "                    continue\n",
    "                eta = 2.0 * dataMatrix[i,:]*dataMatrix[j,:].T - dataMatrix[i,:]*dataMatrix[i,:].T - dataMatrix[j,:]*dataMatrix[j,:].T\n",
    "                if eta >= 0: \n",
    "                    #print \"eta>=0\"\n",
    "                    continue\n",
    "                alphas[j] -= labelMat[j]*(Ei - Ej)/eta\n",
    "                alphas[j] = clipAlpha(alphas[j],H,L)\n",
    "                if (abs(alphas[j] - alphaJold) < 0.00001):\n",
    "                    #print \"j not moving enough\"\n",
    "                    continue\n",
    "                alphas[i] += labelMat[j]*labelMat[i]*(alphaJold - alphas[j])#update i by the same amount as j\n",
    "                                                                        #the update is in the oppostie direction\n",
    "                b1 = b - Ei- labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[i,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[i,:]*dataMatrix[j,:].T\n",
    "                b2 = b - Ej- labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[j,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[j,:]*dataMatrix[j,:].T\n",
    "                if (0 < alphas[i]) and (C > alphas[i]): b = b1\n",
    "                elif (0 < alphas[j]) and (C > alphas[j]): b = b2\n",
    "                else: b = (b1 + b2)/2.0\n",
    "                alphaPairsChanged += 1\n",
    "                #print \"iter: %d i:%d, pairs changed %d\" % (iter,i,alphaPairsChanged)\n",
    "        if (alphaPairsChanged == 0): iter += 1\n",
    "        else: iter = 0\n",
    "        #print \"iteration number: %d\" % iter\n",
    "    return b,alphas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total time running 6.568000 seconds\n(100L, 1L)\n[[ 0.05805216  0.28772265  0.07965433  0.26612048]]\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "\n",
    "t0 = time.time()\n",
    "b,alphas = smoSimple(x,y.ravel(),0.6,0.001,40)\n",
    "t1 = time.time()\n",
    "print \"Total time running %f seconds\" %(t1-t0)\n",
    "print alphas.shape\n",
    "print alphas[alphas>0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2L, 1L)\n[[ 0.77418358]\n [-0.25633008]]\n"
     ]
    }
   ],
   "source": [
    "def calcWs(alphas,dataArr,classLabels):\n",
    "    X = np.mat(dataArr)\n",
    "    labelMat = np.mat(classLabels).transpose()\n",
    "    m,n = np.shape(X)\n",
    "    w = np.zeros((n,1))\n",
    "    for i in range(m):\n",
    "        w += np.multiply(alphas[i]*labelMat[i],X[i,:].T)\n",
    "    return w\n",
    "\n",
    "w = calcWs(alphas,x,y.ravel())\n",
    "print w.shape\n",
    "print w\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEKCAYAAAD5MJl4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt81PWV8PHPgQSCIQEEuWiMiIRaihrLRaNLVS6W1q62\nu3Z7eerjpZbtohBg+9RVXlvx2e3r2W5bbqtWKNWqW9u17mqr66rchFJuQkWrVbkEkIjcREi4hSRz\nnj9++TWTy0xmJr+Z7/wm5/16zSuZye9yomTOnO9VVBVjjDEmWjfXARhjjMk+lhyMMca0YcnBGGNM\nG5YcjDHGtGHJwRhjTBuWHIwxxrThNDmISF8ReUZE3hWRd0SkwmU8xhhjPHmO778QeElVbxaRHsBZ\njuMxxhgDiKtJcCLSB9gK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TUsb1DVQLWq+tXaM4QoOQCTgF2q\neghARP4LuAr4d6dRJe+AiAxR1Q9FZAhw0HVAyUjlPTMrK4d4RGQKXhPBjap60nU8CXgNKBORC0Wk\nB15n3G8dx5QwERG89u53VHWe63iSpar3qmqJqg7F+2+/MkSJAVXdD+wVkU80vTQR+JPDkJL1PnCl\niJzV9G9pIiHqUI/yW+DWpu9vBX7jMJakpPqeGboZ0iKyA+gJfNT00gZV/bbDkDrU9Kl1Ad5IjUdV\n9fuOQ0qYiPwF8DvgjzS32d+nqi+6iyo1InIt8B1V/YLrWJIhIuV4nek9gCrgdlX92G1UiRORB4Cv\n4DVpvA7cqap1bqOKTUR+CVyLt0z3AeB+4DngaaAU2AP8jaq27rR2Lkbs95LCe2bokoMxxpj0C12z\nkjHGmPSz5GCMMaYNSw7GGGPasORgjDGmDUsOxhhj2rDkYExAROQlETkaxpVfjWnNkoMxwfkhcIvr\nIIwJgiUHY5IkImOb1sYvEJHCpr0KRqnqCqDWdXzGBCEr11YyJpup6msi8lvgn4FewL+r6lsdnGZM\nqFhyMCY1/xdv3azTeJvZGJNTrFnJmNT0B3oDRXirvRqTUyw5GJOaxcA/4q2N/wPHsRgTOGtWMiZJ\nIvK/gXpVfappj/B1IjIBeAC4GOgtItXAN1X1ZZexGpMqW5XVGGNMG9asZIwxpg1LDsYYY9qw5GCM\nMaYNSw7GGGPasORgjDGmDUsOxhhj2rDkYIwxpo3/D0GVXqBlDwTLAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x84c1518>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "label1 = np.where(y.ravel() == -1)\n",
    "plt.scatter(x[label1,0],x[label1,1],marker='x',color = 'red',label = '-1')\n",
    "label2 = np.where(y.ravel() == 1)\n",
    "plt.scatter(x[label2,0],x[label2,1],marker='s',color = 'black',label = '1')\n",
    "#画出支持向量\n",
    "supportIndex = np.nonzero(alphas>0)[0]\n",
    "plt.plot(x[supportIndex,0],x[supportIndex,1],'bo',markersize=15,fillstyle='none')\n",
    "\n",
    "#使用已知的参数画出超平面\n",
    "b0 = b[0,0]; w0=w[0,0]; w1=w[1,0]\n",
    "x0 = np.arange(-2.0, 12.0, 0.1)\n",
    "y0 = (-w0*x0 - b0)/w1\n",
    "plt.plot(x0,y0)\n",
    "plt.axis([-2,12,-8,6])\n",
    "\n",
    "plt.xlabel('x1')\n",
    "plt.ylabel('x2')\n",
    "plt.legend(loc = 'upper left')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
